﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using CloudSoft.Extensions;

namespace ERPStore.Exporter.Models.LeadSources
{
	public class GoogleShoppingSource : ERPStore.Models.LeadSourceBase
	{
		public override string Id
		{
			get { return "D36E99D7-CA2E-439d-B594-442D582FE118"; }
		}

		public override string Name
		{
			get { return "Google Shopping"; }
		}

		public override string Description
		{
			get { return "Comparateur de prix Google Shopping"; }
		}

		public override string TrackSourceId
		{
			get { return "gshopping"; }
		}

		public override string Medium
		{
			get { return "cpc"; }
		}

		public override int Order
		{
			get
			{
				return 7;
			}
		}

		public override ERPStore.Models.LeadSourceType LeadSourceType
		{
			get { return ERPStore.Models.LeadSourceType.PriceComparator; }
		}

		public override bool Match(Uri sourceUri, Uri landingUri, out string keywords, out string subHost, out decimal amount)
		{
			subHost = null;
			amount = 0.19m;
			var landingPrms = landingUri.GetParameters();
			var sourcePrms = sourceUri.GetParameters() ?? new System.Collections.Specialized.NameValueCollection();
			keywords = null;

			if (landingPrms.AllKeys.Contains("estid"))
			{
				var estid = landingPrms["estid"];
				if (estid.Equals(TrackSourceId, StringComparison.InvariantCultureIgnoreCase))
				{
					keywords = Uri.UnescapeDataString(sourcePrms["q"] ?? string.Empty);
					keywords = keywords.Replace("+", " ");

					subHost = "Direct";
					return true;
				}
			}

			return false;
		}
	}
}
